package com.shuqi.activity.viewport;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.widget.Gallery;

/**
 * 自定义gallery
 * 
 * @author linyuren
 * 
 */
public class BookSearchGallery extends Gallery {

   

    private ViewPager mPager;

    public ViewPager getmPager() {
        return mPager;
    }
    public void setmPager(ViewPager mPager) {
        this.mPager = mPager;
    }

    /**
     * @param context
     * @param attrs
     */
    public BookSearchGallery(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }

    /**
     * @param context
     * @param attrs &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;
     */
    public BookSearchGallery(Context context, AttributeSet attrs) {
        super(context, attrs); // TODO Auto-generated constructor stub
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        mPager.requestDisallowInterceptTouchEvent(true);
        return super.dispatchTouchEvent(ev);
    }

    @Override
//    public boolean onTouchEvent(MotionEvent event) {
//        if (MotionEvent.ACTION_UP == event.getAction()) {
//            return false;
//        } else {
//            return true;
//        }
//    }

    public boolean onFling(MotionEvent paramMotionEvent1, MotionEvent paramMotionEvent2,
            float paramFloat1, float paramFloat2) {
        if (paramMotionEvent2.getX() > paramMotionEvent1.getX()) {
            // 往左边滑动
            super.onKeyDown(KeyEvent.KEYCODE_DPAD_LEFT, null);
        } else {
            // 往右边滑动
            super.onKeyDown(KeyEvent.KEYCODE_DPAD_RIGHT, null);
        }
        return false;
    }

}
